package com.ruoyi.tmsdriveracc.service.impl;

import com.ruoyi.tmsdriveracc.domain.AWaybill;
import com.ruoyi.tmsdriveracc.mapper.AWaybillDao;
import com.ruoyi.tmsdriveracc.service.AWaybillService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 货运单表(AWaybill)表服务实现类
 *
 * @author 小何
 * @since 2022-04-24 14:16:58
 */
@Service("aWaybillService")
public class AWaybillServiceImpl implements AWaybillService {
    @Resource
    private AWaybillDao aWaybillDao;

    /**
     * 通过ID查询单条数据
     *
     * @param waybillId 主键
     * @return 实例对象
     */
    @Override
    public AWaybill queryById(Long waybillId) {
        return this.aWaybillDao.queryById(waybillId);
    }

    /**
     * 分页查询
     *
     * @param aWaybill    筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @Override
    public Page<AWaybill> queryByPage(AWaybill aWaybill, PageRequest pageRequest) {
        long total = this.aWaybillDao.count(aWaybill);
        return new PageImpl<>(this.aWaybillDao.queryAllByLimit(aWaybill, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param aWaybill 实例对象
     * @return 实例对象
     */
    @Override
    public AWaybill insert(AWaybill aWaybill) {
        this.aWaybillDao.insert(aWaybill);
        return aWaybill;
    }

    /**
     * 修改数据
     *
     * @param aWaybill 实例对象
     * @return 实例对象
     */
    @Override
    public AWaybill update(AWaybill aWaybill) {
        this.aWaybillDao.update(aWaybill);
        return this.queryById(aWaybill.getWaybillId());
    }

    /**
     * 通过主键删除数据
     *
     * @param waybillId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long waybillId) {
        return this.aWaybillDao.deleteById(waybillId) > 0;
    }
}
